<include file="__PUBLIC__/_header"/>
<link href="__APP_SKIN__js/uploadify/uploadify.css?2" rel="stylesheet" type="text/css" />
<link href="__APP_SKIN__css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="__APP_SKIN__css/font-awesome.min.css" />

<!--[if IE 7]>
<link rel="stylesheet" href="__APP_SKIN__css/font-awesome-ie7.min.css" />
<![endif]-->

<!-- page specific plugin styles -->

<link rel="stylesheet" href="__APP_SKIN__css/jquery-ui-1.10.3.custom.min.css" />

<!-- ace styles -->

<link rel="stylesheet" href="__APP_SKIN__css/ace.min.css" />
<link rel="stylesheet" href="__APP_SKIN__css/ace-rtl.min.css" />
<link rel="stylesheet" href="__APP_SKIN__css/ace-skins.min.css" />

<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->

<!-- inline styles related to this page -->
<!-- ace settings handler -->

<script src="__APP_SKIN__js/ace-extra.min.js"></script>
<body>
<div class="navbar navbar-default" id="navbar">
	<script type="text/javascript">
        try{
            ace.settings.check('navbar' , 'fixed')
        }catch(e){

        }
	</script>
	<include file="__PUBLIC__/_header_title"/><!-- /.container -->
</div>
<div class="main-container" id="main-container">
	<script type="text/javascript">
        try{
            ace.settings.check('main-container' , 'fixed')
        }catch(e){

        }
	</script>

	<div class="main-container-inner">
		<a class="menu-toggler" id="menu-toggler" href="#">
			<span class="menu-text"></span>
		</a>

		<div class="sidebar" id="sidebar">
			<script type="text/javascript">
                try{
                    ace.settings.check('sidebar' , 'fixed')}catch(e){
                }
			</script>
			<include file="__PUBLIC__/_nav"/>
			<!-- /.nav-list -->
		</div>
		<div class="main-content">

			<div class="page-content">
				<div class="page-header">
					<h1> 广告管理 <small> <i class="icon-double-angle-right"></i> 经验分享 </small> </h1>
				</div>
				<!-- /.page-header -->
				<div class="row">
					<div class="col-xs-12">
						<!-- PAGE CONTENT BEGINS -->
						<div class="row">
							<div class="col-xs-12">

								<form id="myform" class="form-horizontal" name="example"  method="post" action="{:Controller::createUrl('qcyjadm/article/add/')}" >
									<input type="hidden" name="data[place_id]" value="{$place_id}">
									<div id="del_attch"></div>
									<table class="table table-bordered table-hover definewidth m10 " style="width: 100%;margin: 10px;">
										<tbody>
										<tr>
											<th class="col-xs-2 col-sm-1">文章标题</th>
											<td colspan="3"><input class="col-xs-10 col-sm-5" id="title" placeholder="文章标题不能为空"  type="text" name="title"  /></td>
										</tr>

										<tr>
											<th>内容</th>
											<td>{$htmls.content_html}</td>
										</tr>
										<tr>
											<th>置顶</th>
											<td>{$htmls.is_top}</td>
										</tr>
										<tr>
                                            <th>状态</th>
                                            <td>
                                               {$htmls.state}
                                            </td>
                                        </tr>
										</tbody>
									</table>
									<table class="table table-bordered table-hover definewidth m10 " style="width: 100%;margin: 10px;">
										<!--<caption style="text-align: left">附件 <b class="arrow icon-angle-down"></b></caption>-->
										<!--<tr>-->
											<!--<th class="col-xs-2 col-sm-1">上传图片</th>-->
											<!--<td >-->
												<!--<a id="b_pic1" idx="1" name="file_upload"  multiple="true" >上传</a>-->
											<!--</td>-->
										<!--</tr>-->
										<tfoot>
										<tr>
											<td colspan="22">
												<div class="col-md-offset-4 col-md-9">
													<button class="btn btn-info"  type="button" onclick="chk_form();">
														<i class="icon-ok bigger-110"></i>
														提交
													</button>
													<button class="btn" type="reset">
														<i class="icon-undo bigger-110"></i>
														重置
													</button>
												</div>
											</td>
										</tr>
										</tfoot>
									</table>
									<!-- 修改 -->
								</form>

							</div>
							<!-- /span -->
						</div>
						<!-- /row -->
					</div>
					<!-- PAGE CONTENT ENDS -->
				</div>
				<!-- /.row -->
			</div>
		</div>
	</div>
</div>

<link href="__SKIN__/js/colorbox/colorbox.css" rel="stylesheet" type="text/css">
<script src="__SKIN__/js/colorbox/colorbox.js" type="text/javascript"></script>
<input type="hidden" id="update_img" value="{$arr['img']}">
<input type="hidden" id="uploadSwf" value="__APP_SKIN__js/uploadify/uploadify.swf">
<input type="hidden" id="uploader" value="{:Controller::createUrl('vis/file/index')}">
<input type="hidden" id="service_url" value="{:Controller::getConfig('file_server_url')}">

<script src="__APP_SKIN__js/jquery-2.0.3.min.js"></script>
<script src="__APP_SKIN__js/bootstrap.min.js"></script>
<script src="__APP_SKIN__js/uploadify/jquery.uploadify.js?12" type="text/javascript"></script>
<script src="__APP_SKIN__js/jquery-ui-1.10.3.custom.min.js"></script>

<script>
    function chk_form(){

        if($('#title').val() ==''){
            $('#title').focus();
            //$('#title-tips').html('标题不能为空');
            return false;
        }
        /* if($('#content').val() ==''){
             $('#content').focus();
             //$('#content-tips').html('标题不能为空');
             return false;
         }*/

       $("#myform").submit();
    }

    function ajax_submit_form(url,obj){

        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: url ,//url
            data: $('#'+obj).serialize(),
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.resultCode == 200) {
                    window.parent.location.reload();
                }else{
                    alert('经验分享添加失败');
                }
            },
            error : function() {
                return false;
            }
        });
    }


    $(function () {

        var url = $('#dataupdate').val();
        $('#dataupdate_button').click(function () {
            var is_img = $('#update_img').val();

            var img = '';
            if (is_img == 1) {
                img = $("input[name='upload_files']").map(function (index, elem) {
                    return $(elem).val();
                }).get().join(',');
                if (img == '') {
                    bootbox.dialog({
                        message: "<span class='btn-sm btn-danger'>请上传图片</span>"
                    });
                    return false;
                }
            }
        })
        upload($("a[name=file_upload]"));
        bind_del_pic();
    })


    function upload(obj) {
        var swf = $("#uploadSwf").val();
        var uploader = $("#uploader").val();
        $(obj).uploadify({
            'height': 140,
            'width': 140,
            'multi': true,
            'formData': {'file_type': 0},
            'swf': swf,    //指定上传控件的主体文件
            'uploader': uploader,    //指定服务器端上传处理文件
            'fileTypeExts': '*.jpg',  //jpeg;*.gif;*.png
            'fileTypeDesc': 'Image Files',
            'fileSizeLimit': '4096KB',
            'buttonText': "",
            'queueSizeLimit': 50,
            //检测FLASH失败调用
            'onFallback': function () {
                alert("您的浏览器未安装FLASH控件，无法上传图片，请安装FLASH控件后再试！");
            },
            //返回一个错误，选择文件的时候触发
            'onSelectError': function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        alert("上传的文件数量已经超出限制的" + $('a[name=file_upload]').uploadify('settings', 'queueSizeLimit') + "个文件！");
                        break;
                    case -110:
                        alert("文件 [" + file.name + "] 大小超出系统限制的" + $('a[name=file_upload]').uploadify('settings', 'fileSizeLimit') + "大小！");
                        break;
                    case -120:
                        alert("文件 [" + file.name + "] 大小异常！");
                        break;
                    case -130:
                        alert("文件 [" + file.name + "] 类型不正确！");
                        break;
                }
            },
            'onUploadError': function (file, errorCode, errorMsg, errorString) {
                alert(errorString);
            },
            'onUploadSuccess': function (file, data, response) {
                var service_url = $("#service_url").val();
                ;
                var jsons = "/2013/" + data;
                if ($(".no_pic").length > 0) {
                    $(".no_pic").remove();
                }
                $("<div style='max-width:200px;height:140px;float: left;text-align: center'><input type='hidden' name='upload_files' value='" + data + "' />" +
                    "<img class='preview-upload-pic' style='height:110px;max-width:160px; margin:5px;' src='" + service_url + jsons + "'/>&nbsp;" + data + "<br/><a href='javascript:void(0);' file_name='" + data + "'class='del_pic'>删除</a><br/><br/><br/></div>").insertBefore($('#' + file.id).parent());
                bind_del_pic();
            }
        });
    }


    function bind_del_pic() {
        $(".del_pic").click(function () {
            $(this).parent().remove();
            $("#del_attch").append("<input type='hidden' name='deled_pic[]' value='" + $(this).attr('file_name') + "' />");
        });
    }

    function showErrorAlert (reason, detail) {
        var msg='';
        if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
        else {
            console.log("error uploading file", reason, detail);
        }
        $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+
            '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
    }

    jQuery(function($){

        $("#islink").change(function() {

            if($('#islink').prop('checked')==true) {
                $('#url').prop('disabled',false);
            }else {
                $('#url').prop('disabled',true);
            }
        });
    });
</script>
</body>
</html>
